Skip to content

fix(core): preserve global model config with custom clients - #3094

Draft
linhongyu510 wants to merge 4 commits into
web-infra-dev:mainfrom
linhongyu510:fix/create-openai-client-global-config
Draft

fix(core): preserve global model config with custom clients#3094
linhongyu510 wants to merge 4 commits into
web-infra-dev:mainfrom
linhongyu510:fix/create-openai-client-global-config

Conversation

@linhongyu510

@linhongyu510 linhongyu510 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve global model configuration when createOpenAIClient is provided without an explicit modelConfig
  • expose the agent-scoped client factory through agent.modelConfigManager, including Playground describe and locate runtimes
  • keep custom client factories isolated between agents that share global model values

Root cause

Agent treated createOpenAIClient alone as a custom model configuration and created an isolated ModelConfigManager. Because that manager had neither an explicit modelConfig nor a registered GlobalConfigManager, it resolved an empty configuration and reported that MIDSCENE_MODEL_NAME was missing.

Simply reusing the global manager would fix model resolution but would drop the agent-scoped factory from public modelConfigManager consumers. Playground builds describe and locate runtimes through that public manager, so observability wrappers such as LangSmith or Langfuse would be silently skipped on those paths.

Solution

Factory-only agents now use an AgentScopedModelConfigManager that delegates model values to globalModelConfigManager and returns a copied configuration with the current agent's createOpenAIClient.

This keeps global overrides and environment updates dynamic, avoids mutating shared cached configurations, and preserves independent factories for multiple agents.

Tests use stubbed environment variables with explicit cache clearing so global configuration state is restored after every case.

Validation

  • pnpm --filter @midscene/core test
    • 150 test files passed
    • 1,564 tests passed, 8 skipped
  • pnpm build
    • 28 projects built successfully
  • pnpm type-check:tests
  • pnpm run lint

Closes #3079.

@linhongyu510
linhongyu510 force-pushed the fix/create-openai-client-global-config branch from 916fc1b to a9e0210 Compare September 4, 2026 13:25
@linhongyu510 linhongyu510 changed the title fix(core): preserve global config for custom OpenAI clients fix(core): preserve global model config with custom clients Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: createOpenAIClient option breaks model configuration

1 participant